package Test;

class MyThread extends Thread{
    @Override
    public void run() {
        while (true){
            System.out.println("我的t线程");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
class Run implements Runnable{
    @Override
    public void run() {
        while (true){
            System.out.println("我是r线程");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class Test05 {

    public static void main4(String[] args) {
        Thread t = new Thread(()->{
            while (true){
                System.out.println("我是t线程");
            }
        });
        t.start();
    }
    //继承Thread,使用匿名内部类
    public static void main3(String[] args) {
        Thread t = new Thread(){
            @Override
            public void run() {
                while (true){
                    System.out.println("我是t线程");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t.start();
    }
    public static void main2(String[] args) throws InterruptedException {
        Run r = new Run();
        Thread t = new Thread(r);
        t.start();
        while (true){
            System.out.println("我是main线程");
            Thread.sleep(1000);
        }
    }
    public static void main1(String[] args) throws InterruptedException {
        MyThread t = new MyThread();
        t.start();
        while (true){
            System.out.println("我是main线程");
            Thread.sleep(1000);
        }
    }
}
